var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all) __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if ((from && typeof from === 'object') || typeof from === 'function') {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, {
          get: () => from[key],
          enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
        });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, '__esModule', { value: true }), mod);

// src/Breadcrumbs/useMatches.ts
var useMatches_exports = {};
__export(useMatches_exports, {
  default: () => useMatches_default,
});
module.exports = __toCommonJS(useMatches_exports);
var import_hooks = require('@szzj/hooks');
var import_react = require('react');
var import_react_router_dom = require('react-router-dom');
function useMatches({ pathname = '/', base = '/', routes }) {
  const { findNode, toArray, findPosterityNodesByKey, findAncestorNodes } = (0,
  import_hooks.useTree)(routes, {
    uniqueKey: 'path',
    childrenKey: 'routes',
  });
  const baseRoute = (0, import_react.useMemo)(() => findNode(base), [findNode, base]);
  const baseChildRoutes = (0, import_react.useMemo)(
    () => (base && baseRoute ? findPosterityNodesByKey(base) : toArray(routes)),
    [findPosterityNodesByKey, toArray, baseRoute, base, routes],
  );
  const matchedRoute = (0, import_react.useMemo)(() => {
    const result = baseChildRoutes.find((route) => {
      var _a;
      return (
        !((_a = route.routes) == null ? void 0 : _a.length) &&
        !!(0, import_react_router_dom.matchPath)({ path: route.path }, pathname) &&
        route.path.split('/').length === pathname.split('/').length
      );
    });
    return result;
  }, [baseChildRoutes, pathname]);
  const matches = (0, import_react.useMemo)(() => {
    return (matchedRoute == null ? void 0 : matchedRoute.path)
      ? [
          baseRoute,
          ...findAncestorNodes(matchedRoute.path)
            .filter((route) => route.path.length > base.length)
            .reverse(),
          matchedRoute,
        ]
          .filter((it) => !!it)
          .filter((it) => it === baseRoute || !!it.title)
      : [];
  }, [baseRoute, findAncestorNodes, matchedRoute, base]);
  return matches;
}
var useMatches_default = useMatches;
